home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / asm / alib11b.zip / CODE1.ZIP / DEBUG / WATCH.ASM < prev   
Assembly Source File  |  1994-10-03  |  11KB  |  422 lines

  1. ;
  2. ; WATCH is a resident program that watches for interrupts you specify
  3. ; and prints a quick note to the printer.  The program contains a
  4. ; table (ctrl_tbl) which must be modified to specify which interrupts
  5. ; to watch.  Programmed by Jeff Owens, kowens@teleport.com
  6. ;---------------------------------------------------------------------------
  7. ;
  8. code           segment
  9.                assume cs:code,ds:code
  10.                org 100h
  11. entry:         jmp initialize
  12.  
  13. ;
  14. ; The following buffer is used to store interrupt information before it
  15. ; is sent to the printer.
  16. ;
  17. ibuf_size    equ    2*1800
  18. ibuf        label    byte
  19.         db    ibuf_size dup (0)
  20. ibuf_end    label    byte
  21.  
  22. ibuf_ptr    dw    ibuf
  23. ;
  24. ; the following table is the key to program execution, entries control
  25. ; which interrupts are trapped and how processing occurs.  The interrupt
  26. ; points at table "call" entry.
  27. ;
  28. ctable    struc
  29.  inum     db    ?            ;interrupt number
  30.       db    0e8h            ;call op code
  31.  process dw    ?            ;process address
  32.      db    0eah,0,0,0,0        ;far jump
  33. rtn_off    equ    5
  34. rtn_seg    equ    7
  35. ctable    ends
  36.  
  37. ctrl_tbl    label    byte
  38.  ctable<08h,,process1,,>
  39.  ctable<13h,,process1,,>
  40.  ctable<15h,,process1,,>
  41.  ctable<16h,,process1,,>
  42.  ctable<17h,,process1,,>
  43.  ctable<18h,,process1,,>
  44.  ctable<19h,,process1,,>
  45.  ctable<1ah,,process1,,>
  46.  ctable<1ch,,process1,,>
  47.  ctable<20h,,process1,,>
  48.  ctable<21h,,printint,,>
  49.  ctable<22h,,process1,,>
  50.  ctable<25h,,printint,,>
  51.  ctable<26h,,process1,,>
  52. ; ctable<28h,,process1,,>        ;dos idle
  53.  ctable<2ah,,process1,,>
  54.  ctable<2bh,,process1,,>
  55.  ctable<2ch,,process1,,>
  56.  ctable<2dh,,process1,,>
  57.  ctable<2eh,,process1,,>
  58.  ctable<2fh,,printint,,>
  59.  ctable<31h,,process1,,>
  60.  ctable<32h,,process1,,>
  61.  ctable<33h,,process1,,>
  62.  ctable<34h,,process1,,>
  63.  ctable<35h,,process1,,>
  64.  ctable<36h,,process1,,>
  65.  ctable<37h,,process1,,>
  66.  ctable<38h,,process1,,>
  67.  ctable<39h,,process1,,>
  68.  ctable<40h,,process1,,>
  69.  ctable<54h,,process1,,>
  70.     db    -1            ;end of table
  71. ;
  72. ; printer information
  73. ;
  74. prn_buf        db    'xxxx '        ;current print line
  75. prn_buf_ptr    dw    0        ;non zero if prn_buf has data
  76. column_counter    db    0        ;counts 16 columns accross
  77.  
  78.     
  79. ax_save        dw    0
  80. bx_save        dw    0
  81. cx_save        dw    0
  82. dx_save        dw    0
  83. si_save        dw    0
  84. di_save        dw    0
  85. bp_save        dw    0
  86. ds_save        dw    0
  87. es_save        dw    0
  88.  
  89. ax_save1    dw    0
  90. bx_save1    dw    0
  91. bp_save1    dw    0
  92. es_save1    dw    0
  93.  
  94. lpt1_port    dw    0
  95. ;----------------------------------------------------------------------------
  96. ; minimum process
  97. ;   inputs:  Stack points at return to calling table entry.
  98. ;            No registers are saved.
  99. ;
  100. process1:
  101.     cli
  102.     pushf
  103.     mov    cs:ax_save1,ax
  104.     mov    cs:bx_save1,bx
  105.     mov    cs:bp_save1,bp
  106.     mov    cs:es_save1,es
  107.     
  108.         mov     ax,0
  109.         mov     es,ax
  110.         test    byte ptr es:[417h],40h
  111.         jz    process1_exit                   ;jmp if no caps lock
  112.  
  113.     mov    cs:prime_flag,1            ;set data collection state
  114.     mov    bx,cs
  115.     mov    es,bx
  116.     mov    bp,sp
  117.     mov    bx,ss:[bp+2]            ;get return address
  118.     sub    bx,4                ;point at start of table
  119.  
  120.     mov    ah,cs:[bx.inum]            ;get this interrupt number
  121.     mov    al,byte ptr cs:ax_save1+1    ;get origional -ah-
  122.  
  123.     mov    bx,cs:ibuf_ptr
  124.     mov    word ptr cs:[bx],ax        ;save data in buffer
  125.     add    cs:ibuf_ptr,2
  126.     cmp    bx,offset ibuf_end-2
  127.     jb    process1_exit            ;jmp if not at end yet
  128.     mov    cs:ibuf_ptr,offset ibuf
  129.  
  130. process1_exit:
  131.     mov    es,cs:es_save1
  132.     mov    bp,cs:bp_save1
  133.     mov    bx,cs:bx_save1
  134.     mov    ax,cs:ax_save1
  135.     popf
  136.     sti
  137.     ret
  138. ;----------------------------------------------------------------------------
  139. ; print stored data
  140. ;   inputs:  Stack points at return to calling table entry.
  141. ;            No registers are saved.
  142. ;
  143. prime_flag    db    0            ;0=uprimed
  144. ;                                                1=collecting data
  145. ;                                                2=print inprocess
  146. local_ibuf_ptr    dw    0
  147.  
  148. printint:
  149.     pushf
  150.     mov    cs:ax_save,ax
  151.     mov    cs:bx_save,bx
  152.     mov    cs:cx_save,cx
  153.     mov    cs:dx_save,dx
  154.     mov    cs:bp_save,bp
  155.     mov    cs:es_save,es
  156.     
  157.         mov     ax,0
  158.         mov     es,ax
  159.         test    byte ptr es:[417h],40h
  160.         jz    start_printing
  161.     jmp     printint_exit                   ;jmp if caps lock
  162.  
  163. start_printing:
  164.     cmp    cs:prime_flag,0
  165.     je    printint_exit            ;jmp if no data saved yet
  166.     cmp    cs:prime_flag,2
  167.     je    check_for_ibuf_data        ;jmp if print in process
  168.     mov    ax,cs:ibuf_ptr
  169.     mov    cs:local_ibuf_ptr,ax
  170.     mov    cs:prime_flag,2
  171.     jmp    do_crlf
  172. check_for_ibuf_data:
  173. ;
  174. ; check if existing print data is avail.
  175. ;
  176.     cmp    cs:prn_buf_ptr,0
  177.     je    extract_ibuf_data        ;jmp if no print data ready
  178. print_entry:
  179.     mov    bx,cs:prn_buf_ptr
  180.     mov    al,byte ptr cs:[bx]        ;get print data
  181.     call    print_char            ;try to print next char.
  182.     jc    printint_exit            ; jmp if printer busy
  183. ;
  184. ; one char. in prn_buf was printed, update pointer
  185. ;
  186.     inc    bx
  187.     mov    cs:prn_buf_ptr,bx        ;update print pointer
  188.     cmp    bx,offset prn_buf+5
  189.     jne    print_entry            ;jmp if more to print
  190. ;
  191. ; check if final column printed
  192. ;
  193.     mov    al,cs:column_counter
  194.     inc    al
  195.     mov    cs:column_counter,al
  196.     cmp    al,15                ;check if last column
  197.     je    do_crlf
  198.     cmp    al,16
  199.     jne    keep_printing            ;jmp if more data on line
  200.     mov    cs:column_counter,0
  201.     jmp    keep_printing            ;jmp if starting a new line
  202. do_crlf:
  203.     mov    word ptr cs:prn_buf,0a0dh
  204.     mov    word ptr cs:prn_buf+2,0
  205.     mov    cs:prn_buf_ptr,offset prn_buf
  206.     jmp    printint_exit
  207. keep_printing:
  208.     mov    cs:prn_buf_ptr,0        ;disable prt_buf
  209.     jmp    printint_exit
  210. ;
  211. ; ibuf_ptr points at next store point, use as print starting point
  212. ;
  213. extract_ibuf_data:
  214.     mov    bx,cs:local_ibuf_ptr
  215.     add    cs:local_ibuf_ptr,2        ;move pointer forward
  216.     cmp    bx,offset ibuf_end -2
  217.     jb    ck_for_data            ;jmp if not at end of buffer
  218.     mov    cs:local_ibuf_ptr,offset ibuf
  219. ck_for_data:
  220.     cmp    word ptr cs:[bx],0
  221.     je    printint_exit            ;jmp if nothing to print
  222. ;
  223. ; ibuf has data to be printed
  224. ;
  225.     mov    cx,word ptr cs:[bx]        ;get print data
  226.     mov    word ptr cs:[bx],0        ; zap data entry printed
  227.     mov    bx,offset prn_buf        ;get data storage point
  228.     mov    word ptr cs:prn_buf_ptr,bx    ;store pointer to data
  229.     call    word_to_hex_ascii
  230.     jmp    print_entry
  231. printint_exit:
  232.     mov    es,cs:es_save
  233.     mov    bp,cs:bp_save
  234.         mov     dx,cs:dx_save
  235.     mov    cx,cs:cx_save
  236.     mov    bx,cs:bx_save
  237.     mov    ax,cs:ax_save
  238.     popf
  239.     ret
  240. ;-------------------------------------------
  241. ; print char. in -al-
  242. ;    output - carry set if printer busy and char. not printed.
  243. ;           - register -dx- changed
  244. ;
  245. print_char:
  246.     push    ax
  247. ;    mov    dx,0
  248. ;    mov    ah,2
  249. ;    int    17h            ;get printer status
  250. ;    test    ah,80h
  251. ;    jz    busy_exit        ;exit if printer busy
  252. ;    pop    ax
  253. ;    mov    ah,0
  254. ;    int    17h
  255.  
  256.     mov    dx,cs:lpt1_port
  257.     inc    dx            ;select status port 379
  258.     in    al,dx            ;read printer status
  259.     test    al,80h
  260.     jz    busy_exit
  261.     pop    ax
  262.     dec    dx            ;move to printer port
  263.     out    dx,al            ;print char.
  264.  
  265.     mov    dx,cs:lpt1_port
  266.     add    dx,2            ;select data port 37a        
  267.     mov    al,0dh
  268.     out    dx,al
  269.     out    dx,al
  270.     mov    al,0ch
  271.     out    dx,al
  272.     out    dx,al
  273.     clc
  274.     jmp    pc_exit
  275. busy_exit:
  276.     pop    ax
  277.     stc
  278. pc_exit:
  279.     ret
  280.  
  281. ;-----------------------------------------------------------------------
  282. ; subroutine to convert byte to hex ascii
  283. ;  inputs   AL  = hex
  284. ;         cs:bx = storage point
  285. ;
  286. byte_to_hex_ascii:
  287.     mov    ah,al            ;save data for later
  288.     and    al,0fh            ;isolate low nibble
  289.     add    al,'0'
  290.     cmp    al,'9'
  291.     jle    next_nibble        ;jump if conversion ok
  292.     add    al,'A'-'9'-1
  293. next_nibble:
  294.     xchg    ah,al
  295.     shr    al,1            ;right
  296.     shr    al,1            ;  justify
  297.     shr    al,1            ;     high
  298.     shr    al,1            ;        nibble
  299.     add    al,'0'
  300.     cmp    al,'9'
  301.     jle    hex_store        ;jump if conversion ok
  302.     add    al,'A'-'9'-1
  303. hex_store:
  304.     mov    byte ptr cs:[bx],al
  305.     inc    bx
  306.     mov    byte ptr cs:[bx],ah
  307.     inc    bx
  308.     ret
  309. ;---------------------------------------------------------------------------
  310. ; subroutine to convert word to hex ascii
  311. ;  inputs   cx  = hex word
  312. ;         cs:bx = store pointer
  313. ;
  314. word_to_hex_ascii:
  315.     mov    al,ch            ;get high byte
  316.     call    byte_to_hex_ascii    ;convert and store one byte
  317.     mov    al,cl            ;get low byte
  318.     call    byte_to_hex_ascii    ;convert and store one byte
  319.     ret
  320. ;--------------------------------------------------------------------------
  321. ;------------------------------------------------------------------------------
  322. ; INITIALIZE grabs the needed vectors, then reserves enough memory for
  323. ; the program to remain resident.
  324. ;------------------------------------------------------------------------------
  325. initialize:
  326. ;!    int    3
  327.         mov     ax,cs
  328.         mov     ds,ax
  329.         mov     es,ax
  330.         call    check_printer
  331.         jz    printer_ok
  332.     mov    ah,9
  333.     mov    dx,offset printer_msg
  334.     int    21h
  335.     mov    ax,4c00h
  336.     int    21h
  337. printer_ok:
  338. ;
  339. ; grab needed interrupt vectors.  See table at start of program
  340. ;
  341.     mov    si,offset ctrl_tbl    ;point at first table entry
  342. grab_int_loop:
  343.     cmp    [si.inum],-1
  344.     je    grab_int_done        ;jmp if end of table
  345. ;
  346. ; fix table address for process to call
  347. ;
  348.     mov    ax,[si.process]
  349.     sub    ax,si            ;compute delta
  350.     sub    ax,4            ;adjust for table entry
  351.     mov    [si.process],ax
  352. ;
  353. ; get current vector contents
  354. ;    
  355.     mov    al,[si.inum]
  356.     mov    ah,35h
  357.     int    21h            ;get vector in es:bx
  358.     mov    word ptr ds:[si+rtn_off],bx
  359.     mov    word ptr ds:[si+rtn_seg],es
  360. ;
  361. ; stuff our process address in vector
  362. ;
  363.     mov    ax,cs
  364.     mov    es,ax
  365.     mov    dx,si
  366.     inc    dx            ;move to process point
  367.     mov    al,[si.inum]
  368.     mov    ah,25h
  369.     int    21h
  370.  
  371.     add    si,size ctable
  372.     jmp    grab_int_loop
  373.     
  374. grab_int_done:
  375.     mov    ax,cs
  376.     mov    es,ax
  377.     mov    ds,ax
  378.     mov    dx,offset signon_msg
  379.     mov    ah,9
  380.     int    21h
  381. ;
  382. ; save printer port adr
  383. ;
  384.     mov    ax,0
  385.     mov    es,ax
  386.     mov    ax,word ptr es:[408h]
  387.     mov    cs:lpt1_port,ax
  388. ;        
  389. ; Exit by TSR int 31h.
  390. ;
  391.                 mov    dx,offset initialize
  392.                 add    dx,15
  393.                 mov    cl,4
  394.                 shr    dx,cl
  395.                 mov    ax,3100h
  396.                 int    21h
  397. ;-----------------------------------------------------------------------------
  398. printer_msg    label    byte
  399.     db    0dh,0ah
  400.     db    ' This program requires the printer to be online and ready.',0dh,0ah
  401.     db    ' Aborting without installing',0dh,0ah,'$'
  402. signon_msg    label    byte
  403.     db    0dh,0ah
  404.     db    ' Interrupt quick summary print.',0dh,0ah
  405.     db    '    Caps lock on = collect data',0dh,0ah
  406.     db    '    Caps lock off = print data',0dh,0ah,'$'
  407. ;-----------------------------------------------------------------------------
  408. ; check if printer ready
  409. ;  inputs:  none
  410. ;  outputs: ah = 0 if printer ready (zero flag set)
  411. ;
  412. check_printer:
  413.     mov    dx,0            ;check printer #1 (lpt1)
  414.     mov    ah,2            ;get printer status code
  415.     int    17h            ;call bios
  416.     and    ah,38h            ;check if out of paper, online,error
  417.     xor    ah,10h            ;reverse online bit state
  418.     ret
  419. ;-----------------------------------------------------------------------│-
  420. code            ends
  421.         end     entry
  422.